#Classifier using multidimensional probability densities

#given training and testsets reduced to meaningful columns: [ classNo, attr, attr, ...., attr ]
#result matrix contains two rows: 1st: occurencies of each class in the testset, 2nd: classification errors within each class
#
#train - matrix of samples(rows) and their relevant attributes (cols) prepended by class id (1st col)
#test - same as above 
function results = coreTask2(train,test,apriori=[0.25,0.25,0.25,0.25])
    occurencies=[0,0,0,0];
    mistakes=[0,0,0,0];

    #divide the training set
    train1=train(train(:,1)==1,:);
    train2=train(train(:,1)==2,:); 
    train3=train(train(:,1)==3,:); 
    train4=train(train(:,1)==4,:);

          M1=mean(train1(:,2:end));
          C1=cov(train1(:,2:end));
          M2=mean(train2(:,2:end));
          C2=cov(train2(:,2:end));
          M3=mean(train3(:,2:end));
          C3=cov(train3(:,2:end));
          M4=mean(train4(:,2:end));
          C4=cov(train4(:,2:end));

          for e=2:size(test,1)
              scores=[ apriori(1,1)*mvnpdf(test(e,2:end),M1,C1),
                       apriori(1,2)*mvnpdf(test(e,2:end),M2,C2),
                       apriori(1,3)*mvnpdf(test(e,2:end),M3,C3),
                       apriori(1,4)*mvnpdf(test(e,2:end),M4,C4)];
              [classVal,classNo]=max(scores);
              if(classNo!=test(e,1))
                  mistakes(1,test(e,1))+=1;                
              endif;
              occurencies(1,test(e,1))+=1;
          end;
    results=[occurencies;mistakes];
end;
